/**
 * 
 */
package org.rollinitiative.d20web.charactersheet.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;

/**
 * @author bebopjmm
 *
 */
public class SkillsView extends Composite
{
    private final FlexTable skillsTable_ = new FlexTable();
    
    public SkillsView ()
    {
        // Setup the table
        skillsTable_.setCellSpacing(1);
        skillsTable_.setCellPadding(1);
        skillsTable_.setWidth("50%");
        

        // Hook up events.

        initWidget(skillsTable_);
        initSkillsTable(); 
    }
    
    private void initSkillsTable()
    {
        
        // Create the header row.
        skillsTable_.setText(0, 0, "Skill");
        skillsTable_.setText(0, 1, "Modifier");
      
    }

    public void setCharacter(SkillsData skills)
    {
        // Update content
        int row = 1;
        SkillEntry[] skill = skills.getSkills();
        for (SkillEntry skillEntry : skill) {
            skillsTable_.setText(row, 0, skillEntry.getSkillName());
            skillsTable_.setText(row++, 1, modifier(skillEntry.getModifier()));
        }
        
    }
    
    public String modifier(int modifier) {
        if (modifier > -1) {
            return "+" + modifier;
        }
        else {
            return "" + modifier;
        }
    }
}
